package com.sixth.controller;

import com.sixth.annotation.PageInfoAdvice;
import com.sixth.bean.MarketComment;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author qys
 * @Description
 * @date 2022/9/9 10:48
 */
@RestController
@RequestMapping("admin/comment")
public class AdminCommentController {
    @Autowired
    CommentService commentService;

    @GetMapping("list")
    public BaseRespVo adminCommentList(BasePageInfo basePageInfo, String userId, String valueId) {
        // 判断参数合法性，不是数字，直接返空
        if (userId != null && !userId.equals("")) {
            try {
                Integer.parseInt(userId);
            }
            catch (NumberFormatException e) {
                return BaseRespVo.ok();
            }
        }
        if (valueId != null && !valueId.equals("")) {
            try {
                Integer.parseInt(valueId);
            }
            catch (NumberFormatException e) {
                return BaseRespVo.ok();
            }
        }
        Object adminCommentListVOList = commentService.adminCommentList(basePageInfo, userId, valueId);
        return BaseRespVo.ok(adminCommentListVOList);
    }

    @PostMapping("delete")
    public BaseRespVo adminCommentDelete(@RequestBody MarketComment marketComment) {
        int code = commentService.adminCommentDelete(marketComment);
        return BaseRespVo.ok();
    }
}
